Help Alex minimize the cost to transform one document into another
Help Alex find the minimum cost to transform one document (doc1) into another (doc2) using insertion (cost 3), deletion (cost 2), or substitution (cost 5).
doc1:
doc2:
Output: 5 (substitute cār)
doc1:
doc2:
Output: 20 (multiple operations)
| \ | 0 | r | a |
|---|---|---|---|
| 0 | 0 | 3 | 6 |
| c | 2 | 5 | 6 |
| a | 4 | 7 | 5 |
Cost: 5 (substitute cār)
For filling the DP table (n, m are string lengths)
For the DP table
doc1:
doc2:
Example 1: doc1 = "cat", doc2 = "rat" ā 5
Example 2: doc1 = "hello", doc2 = "world" ā 20
For filling the DP table
For the DP table